from config import BASE_HOST
import logging

class RegLoginApi:

    def __init__(self, ses):
        self.ses = ses

    # 获取图片验证码接口

    def get_img_verify_code(self, r):
        url = BASE_HOST + f'/common/public/verifycode1/{r}'
        resp = self.ses.get(url=url)
        logging.info(f'获取图片验证码接口返回的响应状态码:{resp.status_code}')
        return resp

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone_v, img_code_v, type_v='reg'):
        url = BASE_HOST + '/member/public/sendSms'
        data_phone = {'phone': phone_v,
                      'imgVerifyCode': img_code_v,
                      'type': type_v
                      }
        resp = self.ses.post(url=url,data=data_phone )
        resp_dict=resp.json()
        logging.info(f'获取短信验证码接口返回的响应状态码:{resp.status_code}')
        logging.info(f'获取短信验证码接口返回的响应体数据:{resp_dict}')
        return resp
    # 注册接口
    def user_register(self, form_dict):
        url=BASE_HOST+'/member/public/reg'
        resp = self.ses.post(url=url,data=form_dict)
        logging.info(f'注册接口返回的响应体数据:{resp.json()}')
        return resp
    # 登录接口
    def user_login(self, username_v, pwd_v):
        url = BASE_HOST + '/member/public/login'
        data_phone = {'keywords': username_v,
                      'password': pwd_v
                      }
        resp = self.ses.post(url=url, data=data_phone)
        resp_dict = resp.json()
        logging.info(f'登录接口返回的响应状态码:{resp.status_code}')
        logging.info(f'登录接口返回的响应体数据:{resp_dict}')
        return resp


